package org.example.utils;

import org.example.constants.Constants;
import org.example.constants.NameConstants;
import org.example.factory.messagequeue.UserFactory;

import java.util.List;
import java.util.Random;

/**
 * @author huangy
 * @description 随机工具类
 * @since 2022/11/10 15:49
 **/
public class RandomUtils {

    //随机对象
    public static final Random RANDOM = new Random();

    /*
     * @description 随机生成标签
     * @author huangy
     * @since 2022/11/10 17:10
     * @return java.lang.String
     **/
    public static String randomTag() {
        List<String> tags = Constants.RocketMqConstants.TAGS;
        return tags.get(RANDOM.nextInt(tags.size()));
    }

    /*
     * @description 随机0/1
     * @author huangy
     * @since 2022/11/11 17:00
     * @return int
     **/
    public static int randomZeroOrOne() {
        return RANDOM.nextBoolean() ? 1 : 0;
    }

    /*
     * @description 随机生成房间类型
     * @author huangy
     * @since 2022/11/10 17:10
     * @return java.lang.String
     **/
    public static int randomRoomType() {
        List<Integer> roomTypes = Constants.RocketMqConstants.ROOM_TYPES;
        return roomTypes.get(RANDOM.nextInt(roomTypes.size()));
    }

    /*
     * @description 随机账号
     * @author huangy
     * @since 2022/11/10 17:01
     * @return java.lang.String
     **/
    public static String randomUsername() {
        String[] usernames = UserFactory.USER_NAMES;
        return usernames[RANDOM.nextInt(usernames.length)];
    }

    /*
     * @description 随机中文名称
     * @author huangy
     * @since 2022/11/10 16:46
     * @return java.lang.String
     **/
    public static String randomChineseName() {
        String surname = randomSurname();
        String name = randomName();
        //判断是否生成两个字的名字
        if (RANDOM.nextBoolean()) {
            name += randomName();
        }
        return surname + name;
    }

    /*
     * @description 随机姓
     * @author huangy
     * @since 2022/11/10 16:41
     * @return java.lang.String
     **/
    private static String randomSurname() {
        String[] surname = NameConstants.SURNAME;
        return surname[RANDOM.nextInt(surname.length)];
    }

    /*
     * @description 随机名
     * @author huangy
     * @since 2022/11/10 16:43
     * @return java.lang.String
     **/
    private static String randomName() {
        String[] name = NameConstants.NAME;
        return name[RANDOM.nextInt(name.length)];
    }

    private RandomUtils() {
        throw new UnsupportedOperationException();
    }

}
